/*    */ package my.rummySave;
/*    */ 
/*    */ import java.io.File;
/*    */ import java.io.FileInputStream;
/*    */ import java.io.ObjectInputStream;
/*    */ import javax.swing.JFileChooser;
/*    */ import javax.swing.JOptionPane;
/*    */ import javax.swing.filechooser.FileSystemView;
/*    */ import my.rummyInterface.RummyInterface;
/*    */ 
/*    */ public class Cargar
/*    */ {
/*    */   File filename;
/*    */ 
/*    */   public static File getWorkingDirectory(String applicationName)
/*    */     throws Exception
/*    */   {
/* 23 */     JFileChooser fr = new JFileChooser();
/* 24 */     FileSystemView fw = fr.getFileSystemView();
/* 25 */     File userDirectory = fw.getDefaultDirectory();
/* 26 */     String userHome = userDirectory.getPath() + "/Rummy/Juegos Guardados/";
/*    */ 
/* 28 */     if (!new File(userHome).exists())
/*    */     {
/* 30 */       throw new Exception("No existe el directorio");
/*    */     }
/* 32 */     File workingDirectory = new File(userHome + applicationName);
/* 33 */     return workingDirectory;
/*    */   }
/*    */ 
/*    */   public Cargar(File file, RummyInterface principal)
/*    */   {
/*    */     try
/*    */     {
/* 41 */       this.filename = file;
/*    */     }
/*    */     catch (Exception e)
/*    */     {
/* 45 */       JOptionPane.showMessageDialog(principal, e.getMessage());
/*    */     }
/* 47 */     JuegoSalvar juego = null;
/* 48 */     FileInputStream fis = null;
/* 49 */     ObjectInputStream in = null;
/*    */     try
/*    */     {
/* 52 */       fis = new FileInputStream(this.filename);
/* 53 */       in = new ObjectInputStream(fis);
/* 54 */       juego = (JuegoSalvar)in.readObject();
/* 55 */       in.close();
/*    */     }
/*    */     catch (Exception ex)
/*    */     {
/* 59 */       ex.printStackTrace();
/*    */     }
/* 61 */     principal.setVisible(false);
/* 62 */     RummyInterface nuevo = juego.darInterface();
/* 63 */     JOptionPane.showMessageDialog(principal, "Se cargo el juego " + this.filename.getName());
/* 64 */     nuevo.setVisible(true);
/*    */   }
/*    */ 
/*    */   public Cargar(String app, RummyInterface principal)
/*    */   {
/*    */     try {
/* 70 */       this.filename = getWorkingDirectory(app + ".rummy");
/*    */     }
/*    */     catch (Exception e)
/*    */     {
/* 74 */       JOptionPane.showMessageDialog(principal, e.getMessage());
/*    */     }
/* 76 */     JuegoSalvar juego = null;
/* 77 */     FileInputStream fis = null;
/* 78 */     ObjectInputStream in = null;
/*    */     try
/*    */     {
/* 81 */       fis = new FileInputStream(this.filename);
/* 82 */       in = new ObjectInputStream(fis);
/* 83 */       juego = (JuegoSalvar)in.readObject();
/* 84 */       in.close();
/*    */     }
/*    */     catch (Exception ex)
/*    */     {
/* 88 */       ex.printStackTrace();
/*    */     }
/* 90 */     principal.setVisible(false);
/* 91 */     RummyInterface nuevo = juego.darInterface();
/* 92 */     JOptionPane.showMessageDialog(principal, "Se cargo el juego " + app);
/* 93 */     nuevo.setVisible(true);
/*    */   }
/*    */ }

/* Location:           C:\Users\Yank\Documents\APO\Rummy\bin\
 * Qualified Name:     my.rummySave.Cargar
 * JD-Core Version:    0.6.0
 */